package work;

import java.util.ArrayList;
import java.util.List;

public class Test01 {
    public String[] split(String str,String splitStr){
        if (str.isEmpty() || splitStr.isEmpty()){
            return new String[]{str};
        }

        List<String> ans = new ArrayList<>();
        int sLength = splitStr.length(),l=0;

        for (int i = 0; i < str.length(); i++){
            if (str.substring(i,i+sLength).equals(splitStr)){
                String substring = str.substring(l, i);
                if (!substring.isEmpty())ans.add(substring);

                i+=sLength;
                l=i;
            }
        }

        String substring = str.substring(l);
        if (!substring.isEmpty())ans.add(substring);
        return ans.toArray(new String[ans.size()]);
    }

    public String join(String[] arr,String splitStr){
        if (arr == null || arr.length == 0) return "";

        StringBuilder builder = new StringBuilder(arr[0]);
        for (int i = 1; i < arr.length; i++){
            builder.append(splitStr).append(arr[i]);
        }
        return builder.toString();
    }
}
